package com.fit.dao.contactPerson;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;

import com.fit.entities.ContactPerson;

public class ContactPersonDAOImpl implements ContactPersonDAO{
	@Inject
	private Session session;
	
	public boolean save(ContactPerson newContactPerson) {
		if (newContactPerson != null) {
			session.save(newContactPerson);
			return true;
		}
		return false;
		
	}

	public boolean delete(ContactPerson contactPerson) {
		if (contactPerson != null) {
			session.delete(contactPerson);
			return true;
		}
		return false;
	}

	public boolean update(ContactPerson contactPerson) {
		if (contactPerson != null) {
			session.update(contactPerson);
			return true;
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	public List<ContactPerson> findAll() {
		return session.createCriteria(ContactPerson.class).list();
		
	}

	public ContactPerson findByID(Long id) {
		if (id != null) {
			return (ContactPerson) session.get(ContactPerson.class, id);
		}
		return null;
	}

	public boolean deleteByID(Long id) {
		ContactPerson cp = findByID(id);
		if (cp != null) {
			delete(cp);
			return true;
		}
		return false;
	}
}
